package com.itheima.reggie.Controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Entity.Orders;
import com.itheima.reggie.Service.*;
import com.itheima.reggie.commom.BaseContext;
import com.itheima.reggie.commom.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    OrdersService ordersService;


    @PostMapping("/submit")
    public Result<String> submit(@RequestBody Orders orders){

        ordersService.submit(orders);

        return Result.success("success");
    }

    @GetMapping("/userPage")
    public Result<Page> userPage(Integer page, Integer pageSize){
        Page<Orders> page1 = new Page<>(page,pageSize);
        Long userId = BaseContext.getCurrentId();
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Orders::getUserId,userId);
        ordersService.page(page1,queryWrapper);

        return Result.success(page1);
    }
}
